local yangwei = fk.CreateSkill{
  name = "ls__yangwei",
  tags = {"ready_skill"},
}

Fk:loadTranslationTable{
  ["ls__yangwei"] = "扬威",
  [":ls__yangwei"] = "<a href='diy_ready_skill'>蓄势技</a>，其他角色的回合开始时，你可视为对其使用刺【杀】；此技能行置时，你与其他角色距离-X（X为重置此技能需弃置的牌数）；持恒技，你使用【杀】杀死一名角色后，可令一名阵营与其相同的角色失去所有体力。",
  ["#lvshi__yangwei-invoke"] = "扬威：你可视为对 %src 使用刺【杀】",
  ["#lvshi__yangwei-target"] = "扬威：你可令一名角色失去所有体力",
  ["@ls__yangwei"] = "扬威",

  ["$ls__yangwei1"] = "长驱直入！",
  ["$ls__yangwei2"] = "从天而降！",
  ["$ls__yangwei3"] = "（击杀）汝命，休矣！",
}

local ls = require "packages/lvshi/utility"
local DIY = require "packages/diy_utility/diy_utility"

yangwei:addEffect(fk.TurnStart, {
  audio_index = { 1, 2 },
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(yangwei.name) and target ~= player and not DIY.isReadying(player, yangwei.name)
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = yangwei.name, prompt = "#lvshi__yangwei-invoke:"..target.id})
  end,
  on_use = function(self, event, target, player, data)
    player.room:useVirtualCard("stab__slash", nil, player, target, yangwei.name, true)
    local n = DIY.getReadyCap(player, yangwei.name) - DIY.getReadyProgress(player, yangwei.name)
    player.room:setPlayerMark(player, "@ls__yangwei", n)
  end,
})

yangwei:addEffect(fk.Death, {
  audio_index = 3,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(yangwei.name, true) and data.killer == player and data.damage
    and data.damage.card and data.damage.card.trueName == "slash"
  end,
  on_cost = function(self, event, target, player, data)
    local to = player.room:askToChoosePlayers(player, {
      skill_name = yangwei.name,
      targets = table.filter(player.room:getAlivePlayers(), function (p)
        return ls.isFriend(target, p) and p.hp > 0
      end),
      min_num = 1,
      max_num = 1,
      prompt = "#lvshi__yangwei-target",
      cancelable = true,
    })
    if #to > 0 then
      event:setCostData(self, {tos = to})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local to = event:getCostData(self).tos[1]
    player.room:loseHp(to, to.hp, yangwei.name)
  end,
})

yangwei:addEffect("distance", {
  correct_func = function(self, from, to)
    if from:hasSkill(yangwei.name, true) and DIY.isReadying(from, yangwei.name) then
      return DIY.getReadyProgress(from, yangwei.name) - DIY.getReadyCap(from, yangwei.name)
    end
  end,
})

yangwei:addEffect(DIY.SkillReadyFinish, {
  can_refresh = function(self, event, target, player, data)
    return data.who == player and data.skill == yangwei
  end,
  on_refresh = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@ls__yangwei", 0)
  end,
})

return yangwei